﻿namespace Launcher.Model

import System

import System.IO

import Boo.Lang.Useful.Attributes

[singleton]
class RankingFile:
"""Description of RankingFile"""
	
	_hash = {}
	
	[getter(Loaded)]
	_loaded as bool
	
	AppRanking[app as string] as int:
		get:
			if _hash.ContainsKey(app):
				return _hash[app]
			else:
				return 0
		set:
			_hash[app] = value
			
	def Load(path as string):
		return unless File.Exists(path)
		
		using f = File.OpenText(path):
			for line as string in f:
				k, v = line.Split(char('='))
				_hash[k] = int.Parse(v)
			
		_loaded = true
		
	def OptimizedLoad(path as string):
		return if _loaded
		Load(path)
		
	def Save(path as string):
		using f = File.CreateText(path):
			for d as Collections.DictionaryEntry in _hash:
				line = "${d.Key}=${d.Value}"
				f.WriteLine(line)
